#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=libxml2
version=2.9.10
xmlts_ver=20130923

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.gz -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	patch -p1 -i $SRC/$name-$version-security_fixes-1.patch

	sed -i '/if Py/{s/Py/(Py/;s/)/))/}' python/{types.c,libxml.c}

	sed -i 's/test.test/#&/' python/tests/tstLastError.py

	sed -i 's/ TRUE/ true/' encoding.c

	./configure --prefix=/usr    \
	            --disable-static \
	            --with-history   \
	            --with-python=/usr/bin/python3 \
	            --with-icu      \
	            --with-threads
	make

	tar xf $SRC/xmlts$xmlts_ver.tar.gz

	make install

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
